package com.example.demo.controller;


import com.alibaba.fastjson.JSONObject;
import com.example.demo.Interface.DataRepo;
import com.example.demo.entity.Data;
import com.example.demo.entity.User;
import com.example.demo.entity.Wendu;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.persistence.Column;
import java.util.ArrayList;
import java.util.List;

@Controller
public class RepData {
    @Resource
    DataRepo dataRepo;

    @RequestMapping(value = "/getall")
    @ResponseBody
    public String repdata() {
        List<Data> dataList = new ArrayList<>();
        List<Data> optionalData = dataRepo.findAll();//查询所有数据
        for (Data data : optionalData) {
                int id = data.id;
                String ip = data.ip;
                String time = data.time;
                String wendu = data.wendu;
                String shidu = data.shidu;
                String equipment = data.equipment;

                Data data1 = new Data();
                data1.time = time;
                data1.shidu = shidu;
                data1.wendu = wendu;
                data1.id = id;
                data1.ip = ip;
                data1.equipment = equipment;

                dataList.add(data1);

            // String s = JSON.toJSONString(userList);
        }
        JSONObject obj = new JSONObject();
        //前台通过key值获得对应的value值
        obj.put("code", 0);
        obj.put("msg", "");
        obj.put("count", 1000);
        obj.put("data", dataList);
        return obj.toJSONString();
    }

    //数据展示页面
    @RequestMapping(value = "/data")
    public String data(){
        return "data";
    }
}
